package com.xm.spring5.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

//增强类
@Component
@Aspect
@Order(3) //优先级 值越小，优先级越高
public class UserProxy {

    //相同切入点抽取
    @Pointcut("execution(* com.xm.spring5.aopanno.User.add(..))")
    public void pointDemo(){}

    //前置通知
    @Before("pointDemo()")
    public void before() {
        System.out.println("before.........");
    }

    @AfterReturning("pointDemo()")
    public void afterReturning() {
        System.out.println("afterReturning......");
    }

    //最终通知
    @After("pointDemo()")
    public void after() {
        System.out.println("after........");
    }

    @AfterThrowing("pointDemo()")
    public void afterThrowing() {
        System.out.println("afterThrowing........");
    }

    //环绕通知
    @Around("execution(* com.xm.spring5.aopanno.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前........");

        proceedingJoinPoint.proceed();

        System.out.println("环绕之后........");
    }
}
